# Maintainer: Philippe Weyland <philippe.weyland@libertysurf.fr>

_realname=gmic
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.9.0
pkgrel=3
pkgdesc="A Full-Featured Open-Source Framework for Image Processing (mingw-w64)"
arch=(any)
url="https://gmic.eu"
license=("CeCILL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-fftw"
         "${MINGW_PACKAGE_PREFIX}-graphicsmagick"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libtiff"
         "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-openexr"
         "${MINGW_PACKAGE_PREFIX}-opencv")
source=("${_realname}-${pkgver}.tar.gz::https://gmic.eu/files/source/${_realname}_${pkgver}.tar.gz"
        "0001-gmic-windows-build.patch")
sha256sums=('6233695f9b27999dcc7cc3aa7480b0f192bd44de85209091a3b4b8a65ae8c4b5'
            '6a662bf159b9903b13e3eaa23d75ebf1db3b8569b4e9be319d8b3711e3928ec5')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-gmic-windows-build.patch"
}

build() {
  rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DBUILD_LIB=ON \
    -DBUILD_LIB_STATIC=OFF \
    -DBUILD_BASH_COMPLETION=OFF \
    -DENABLE_FFMPEG=ON \
    -DENABLE_FFTW=ON \
    -DENABLE_GRAPHICSMAGICK=ON \
    -DENABLE_JPEG=ON \
    -DENABLE_OPENCV=ON \
    -DENABLE_OPENEXR=ON \
    -DENABLE_OPENMP=ON \
    -DENABLE_PNG=ON \
    -DENABLE_TIFF=ON \
    -DENABLE_ZLIB=ON \
    -DENABLE_DYNAMIC_LINKING=ON \
    ../${_realname}-${pkgver}

  make

}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
